<template>
    <div class="otherInfo" data-300-center-top="transform: scale(0.8); opacity: 0"
        data-300-center-center="transform: scale(1); opacity: 1">
        <el-timeline>
            <el-timeline-item :timestamp="new Date(item.timestamp).toLocaleDateString()" placement="top"
                v-for="(item, index) in timeLineList" :key="index">
                <el-card class="item">
                    <h4 @click="goDownload(item.type, item.id, item.address, item.content)">{{ item.content }}</h4>
                </el-card>
            </el-timeline-item>
        </el-timeline>
    </div>
</template>
<script setup>
import { listOtherInfoDownload, listOtherInfo } from '../api/info'
let timeLineList = ref([])
listOtherInfo().then(res => {
    timeLineList.value = res.rows
})

const goDownload = (type, item_id, address, content) => {
    // 下载文件
    if (type == 0) {
        listOtherInfoDownload({
            id: item_id
        }).then(res => {
            const file = new Blob([res], {
                type: "text/plain",
            });
            let url = window.URL.createObjectURL(file);
            let a = document.createElement("a");
            let fileName = content
            document.body.appendChild(a);
            a.href = url;
            a.download = fileName;
            a.click();
            window.URL.revokeObjectURL(url);
        })
    } else if (type == 1) {
        // 跳转链接
        var tempwindow = window.open('_blank'); // 先打开页面
        tempwindow.location = address// 后更改页面地址
    }
}
</script>
<style scoped>
.otherInfo {
    margin-top: 50px;
    width: 60%;
    text-align: left;

}

.item {
    cursor: pointer;
}
</style>